package top.lyc829.zzl_android.ui.thing.dynamic_detail;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.xuexiang.xui.widget.imageview.nine.NineGridImageViewAdapter;
import com.xuexiang.xui.widget.imageview.preview.loader.GlideMediaLoader;

public class NineGridAdapter extends NineGridImageViewAdapter<String>  {
    @Override
    protected void onDisplayImage(Context context, ImageView imageView, String s) {
        Glide.with(imageView.getContext())
                .load(s)
                .apply(GlideMediaLoader.getRequestOptions())
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        //这里给图片设置tag，在图片浏览中不展示未加载完成的图片，防止无法退出，一直出于加载中
                        imageView.setTag("load_success");
                        return false;
                    }
                })
                .into(imageView);
    }
}
